const express = require('express');

const app = express();
app.get('/api/list',(req,res)=>{
  res.json({
    success:true,
    data:['a','b','c','A','C','d']
  })
})

app.post('/api/login',(req,res)=>{

  res.json({
    success:true,
    message:'登录成功'
  })
});

//注册校验手机是否存在
app.get('/api/validate-phone',(req,res)=>{
  const tels = [15555555555,15555555556,15555555557];

  let tel = req.query.tel * 1;


  if(tels.includes(tel)){
    res.json({
      success:false,
      message:'手机号码已被注册'
    })
  }else{
    res.json({
      success:true,
      message:'手机号码可以注册'
    })
  };



});


const list = ['函数看到类似','ahasdak','连连看看到经典','he神传说','hh功夫格斗'];
app.get('/api/search',(req,res)=>{
  let { keyword } = req.query;

  let result = list.filter(item=>item.includes(keyword));

  res.json({
    success:true,
    data:result,
    message:'操作成功'
  });
})



app.listen(8080,()=>{
  console.log('node 服务已运行在 8080端口');
})
